package scantask.client.threeDObjects;

import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.layers.AirspaceLayer;

import java.awt.Color;
import java.util.LinkedList;

import scantask.client.presentationLayer.FunctionalityPanel;
import scantask.client.presentationLayer.Presentation;
import scantask.client.threeDObjects.exceptions.Illegal3DObjectParameter;

public class Prism extends LeafPolygone {
	
	private double _length;

	public Prism(Color color, double xCenter, double yCenter, double buttom,
			double up, int angle, double length, double value) throws Illegal3DObjectParameter {
		super(color, xCenter, yCenter, buttom, up, angle, value);
		
		if (length <= 0) {
			scantask.client.utilities.logging.SingletonLogger.getLogger().warning("Fail illegal length entered");
			throw new Illegal3DObjectParameter();
		}
		
		this._length = length;
		
		
	}

	@Override
	public ComponentPolygone clone() {
		ComponentPolygone ans = null;
		try {
			ans = new Prism(this._color, this._xCenter, this._yCenter,
					this._buttom, this._up, this._angle, this._length, this._value);
		} catch (Illegal3DObjectParameter e) {
			// AdirD - Impossible exception
		}
		
		return ans;
	}

//	@Override
//	public void draw(/** globe **/) {
//		// TODO Auto-generated method stub
//		
//	}
	
	@Override
	public void init3DObject(AirspaceLayer layer){
		super.init3DObject(layer);
		LinkedList<LatLon> list = new LinkedList<LatLon>();
        list.add(LatLon.fromDegrees(this._yCenter + (this._length / 100000), this._xCenter));
        list.add(LatLon.fromDegrees(this._yCenter - (0.5 * (this._length / 100000)),
        		this._xCenter + (0.866 * (this._length / 100000))));
        list.add(LatLon.fromDegrees(this._yCenter - (0.5 * (this._length / 100000)),
        		this._xCenter - (0.866 * (this._length / 100000))));
		this._shape3D = new gov.nasa.worldwind.render.airspaces.Polygon(list);
		this._shape3D.setAltitudes(this._buttom, this._up + Math.abs(this._up - this._buttom)* FunctionalityPanel.DEFAULT_FACTOR);
		Presentation.AppFrame.setAttr(this._shape3D, this._color, Color.ORANGE);
//		this.setDescription(this.getDescription());
	}

}
